struct Solution {}

fn main() {}

use std::collections::{HashMap};

impl Solution {
    pub fn is_valid(s: String) -> bool {
        let mut pair = HashMap::new();
        pair.insert("(".to_string(), ")".to_string());
        pair.insert("[".to_string(), "]".to_string());
        pair.insert("{".to_string(), "}".to_string());

        let mut v: Vec<String> = Vec::new();
        for word in s.chars() {
            let word_s = String::from(word);
            if pair.contains_key(&word_s) {
                v.push(word_s);
            }
            else {
                match v.pop() {
                    Some(temp) => {
                        if pair[&temp] != word_s {
                            return false;
                        }
                    }
                    None => {
                        return false;
                    }
                }
            }
        }
        if v.is_empty() {
            return true;
        }
        return false;
    }
}